package com.example.myapplication.flow

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.lifecycleScope
import com.example.myapplication.R
import com.example.myapplication.databinding.Flow1215activityBinding
import com.orhanobut.logger.Logger
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch

class Flow1215Activity : AppCompatActivity() {
    val _etState = MutableStateFlow("")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var binding =
            DataBindingUtil.setContentView<Flow1215activityBinding>(this, R.layout.flow1215activity)
        binding.editTextTextPersonName.doAfterTextChanged { text ->
            _etState.value = (text ?: "").toString()
        }



        lifecycleScope.launch {
            _etState.sample(500).filter {
                it.isNotBlank()
            }.collect {
                Logger.d("Flow1215Activity===onCreate: 28");
            }
        }

    }
}